%
% This generates a fuzzy number expressed in interval notation as a 2 row, N column vector
% x(:,1) represents the lower bounds of the intervals, x(:,2) represents the upper bounds.
% Thus x(n,:) is a 1 by 2 vector representing an interval of confidence
% x(1,:) is the span of the set
% x(N,:) is the peak, and since this is a triangle x(N,1) == x(N,2)
% The values are distributed (as) equally (as possible giving floating point limitations)
% between low and peak, and high and peak.  
% Note that the endpoint values must be different from the peaks
% N is the granularity as mentioned above, and defaults to 1000.
% Though this is called fuzzy_triangle, the alpha values of each interval is not explicitly
% defined; thus this could be used in conjuction with an alpha generator to produce nonnormal,
% non-triangular fuzzy sets abiet only convex ones where there only exists a single point
% of membership 1 and uniform granularity on the universe of discourse is sufficient.
%
function x = fuzzy_triangle(low, peak, high, N)

if(~exist('N'))
	N = 1000;
end

if (low >= peak)
	error('lower support is greater than the peak');
end

if(high <= peak)
	error('higher support is lesser than the peak');
end


m1 = 1 / (peak - low);
b1 = -low;
m1/(N-1);
x(:,1) = [low:(peak-low)/(N-1):peak].';
x(end,1) = peak; % Floating point error compensation

x(:,2) = [high:-(high-peak)/(N-1):peak].';
x(end,2) = peak;
